
$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'fun/emp/changeOfficeList',
        datatype: "json",
        colModel: [
            { label: '员工ID', name: 'empId', index: "emp_id", width: 90, key: true},
            { label: '员工名', name: 'empName', width: 60 },
            { label: '身份证号', name: 'idCard',sortable: false, width: 100 },
            { label: '部门', name: 'deptName',sortable: false, width: 100 },
            { label: '调整后职名(务)', name: 'office', sortable: false, width: 90 },
            { label: '原职名(务)', name: 'officeAgo', sortable: false, width: 90 },
            { label: '操作人员', name: 'operator', sortable: false, width: 90 },
            { label: '操作时间', name: 'date', sortable: false, width: 90 },
        ],
        viewrecords: true,
        height: 400,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
             $("#jqGrid").setGridParam().hideCol("empId").trigger("reloadGrid");
        },
    });
});

//部门结构树
var dept_ztree;
var dept_setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "deptId",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    }
};

var vm = new Vue({
    el:'#rrapp',
    data:{
        showList: true,
        title: null,
        emp: {
            deptId:null,
            deptName:null,
        },
        pickerOptions: {
            disabledDate(time) {
                return time.getTime() > Date.now();
            }
        },
        fileList: [],
        dialogTableVisible: false,
        dialogFormVisible: false,
        dialogDeptVisible: false,
        dialog: false,
        drawer: false,
        formLabelWidth: '80px',
        timer: null,
        changeOfficeEmpIds:null,
        queryByDate:[],
    },

    methods: {
        query: function () {
            vm.reload();
        },
        update: function (event) {
            var empId = getSelectedRow();
            if(empId == null){
                return ;
            }
            vm.showList = false;
            vm.title = "修改";
            vm.getInfo(empId);
            vm.getDept();
        },
        exportExcel: function (event) {
            var empIds = getSelectedRows();
            if(empIds == null){
                return ;
            }
            $.ajax({
                type: "POST",
                url: baseURL + "fun/emp/exportEmps",
                contentType: "application/json",
                data: JSON.stringify(empIds),
            });
            vm.$message('导出到G://empExcel成功');

        },

        handleCloseDrawer:function(done) {
            vm.dialog=false;
        },
        handleCloseDialog(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                    done();
                })
                .catch(_ => {});
        },
        cancelForm:function() {
            vm.dialog = false;
        },

        handlePreview:function(file) {
            console.log(file);
        },
        handleRemove:function(file, fileList) {
            console.log(file, fileList);
        },
        handleChange(val) {
            console.log(val);
        },
        fresh:function (event)
        {
            $("#jqGrid").trigger("reloadGrid");
            vm.dialogFormVisible=false;
        },
        freshDept:function (event)
        {
            $("#jqGrid").trigger("reloadGrid");
            vm.dialogDeptVisible=false;
        },
        getDept: function(){
            //加载部门树
            $.get(baseURL + "sys/dept/list", function(r){
                dept_ztree = $.fn.zTree.init($("#deptTree"), dept_setting , r);
                var node = dept_ztree.getNodeByParam("deptId", vm.emp.deptId);
                if(node != null){
                    dept_ztree.selectNode(node);
                    vm.emp.deptName = node.name;
                }
            })
        },
        reload: function (event) {
            vm.showList = true;
            if(vm.queryByDate==null)
            {
                vm.queryByDate=['',''];
            }
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'dateStart': vm.queryByDate[0],'dateEnd': vm.queryByDate[1],'deptId':''},
                page:page
            }).trigger("reloadGrid");
        }
    }
});


window.addEventListener("message",function(event){
    vm.showList = true;
    if(vm.queryByDate==null)
    {
        vm.queryByDate=['',''];
    }
    var page = $("#jqGrid").jqGrid('getGridParam','page');
    $("#jqGrid").jqGrid('setGridParam',{
        postData:{'deptId':event.data,'dateStart': vm.queryByDate[0],'dateEnd': vm.queryByDate[1]},
        page:page
    }).trigger("reloadGrid");
}, false);